package com.tianji.learning.task;

import com.tianji.common.utils.CollUtils;
import com.tianji.learning.domain.po.LearningLesson;
import com.tianji.learning.enums.LessonStatus;
import com.tianji.learning.mapper.LearningLessonMapper;
import com.tianji.learning.service.ILearningLessonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * TODO
 *
 * @Author wxy
 * @Date 2024/12/10 21:27
 */
@Component
public class LearningLesssonCheck {
    @Autowired
    private LearningLessonMapper lessonMapper;
    @Autowired
    private ILearningLessonService lessonService;
    @Scheduled(cron = "0 0 3 * * ?")
    public void checkLearningLesson(){
        System.out.println("定时任务工作了");
      List<LearningLesson> list = lessonMapper.findExpireLesson(LocalDateTime.now());
      if(CollUtils.isEmpty(list)){
          return;
      }
        for (LearningLesson lesson : list) {
            lessonService.lambdaUpdate()
                    .eq(LearningLesson::getId,lesson.getId())
                    .set(LearningLesson::getStatus, LessonStatus.EXPIRED)
                    .update();
        }
    }
}
